<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .exit {
            font-size: 12px;
        }

        .exit a {
            color: #212529;
        }

        .cat {
            width: 100px;
            height: 100px;
            border-radius: 50%;
        }

        .username {
            width: 350px;
            height: 250px;
        }

        .file-box {
            position: relative;
            width: 97px;
            height: 27px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }

        .file-box input {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            opacity: 0;
        }

        .file-box span {
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 14px;
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            color: #ccc
        }

        .input {
            width: 42px;
            float: right;
            height: 20px;
            font-size: 12px;
            background: #fff;
            border: 1px solid #ccc;
        }
    </style>
    <link rel="stylesheet" href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
</head>

<body>
    <div class="container">
        <div class="mt-2 clearfix">
            <p class="float-right mr-3">欢迎<span class="pl-1"></span><%= username %><span class="pl-2 exit"><a
                        href="/login?redirect=<%= orig %>">退出登录</a></span></p>

        </div>
        <div class="clearfix">

            <img src="<%= headc %>" alt="" class="cat float-right">
        </div>
        <div class=" float-right mr-2">
            <form action="/posts/postss" method="POST" enctype="multipart/form-data">
                <div class="file-box">
                    <span class="span">更换头像</span>
                    <input type="file" name="headc" class="form-control headc">
                </div>
                <input type="submit" value="确定" class="input">
            </form>
        </div>

        <h1 class=" mb-4">文章列表</h1>

        <a href="/posts/create">添加</a>
        <ul class="list-group mb-4">
            <% for(var i = 0;i<posts.length;i++){ %>
            <li class="list-group-item">
                <h2>
                    <a href="/posts/<%= posts[i]._id %>">
                        <%= posts[i].title %>
                    </a>
                </h2>
                <img src="<%= posts[i].picture %>" alt="" class="username">
                <p><%= posts[i].body %></p>
                <p><%= posts[i].user.username %></p>
            </li>
            <% } %>

        </ul>
        <ul class="pagination ml-5">
            <li class="page-item <%= pageNum === 1 ?'disabled' : '' %>">
                <a class="page-link" href="/posts?pageNum=<%= pageNum === 1 ? 1 :pageNum -1 %>">
                    Prev</a>
            </li>
            <% for(var i = 1;i<= totalPages;i++){ %>
            <li class="page-item <%= pageNum === i ? 'active' : '' %>">
                <a class="page-link" href="/posts?pageNum=<%= i %>"><%=i %></a>
            </li>

            <% } %>
            <li class="page-item <%= pageNum === totalPages ?'disabled' : '' %>">
                <a class="page-link" href="/posts?pageNum=<%= pageNum === totalPages ? totalPages :pageNum +1 %>">
                    Next</a></li>
        </ul>

    </div>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    <script>

        $('.headc').change(() => {
            $('.span').text('已上传')
        })
    </script>
</body>

</html>